<?php

class Base extends Zend_Db_Table{  

	//protected $zenddb;
    protected $_db;
    protected $_table;
	protected $_exe;
    public function __construct() {
    	
		parent::__construct();
    	
		
		$this->_db = $this->getAdapter();
		$dbConfig = $this->_db->getConfig();
		$count=strpos(get_called_class(),"Model"); 
		$str=substr_replace(get_called_class(),"",$count); 
		$this->_table = $dbConfig['prefix'].strtolower($str);
		$this->_exe = $this->_db->select();
		
		$this->_exe->from($this->_table);
		
		
    }   
	
    function orderby($order){
    	$this->_exe->order($order);
    }
    
    function where($where){
    	
        $where = (array) $where;
     
        foreach ($where as $key => $val) {
        	
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $this->_exe->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition
                $this->_exe->where($key, $val);
            }
        }
       
        return $this->_exe;
    }
	
	function limit($count,$offsite){
		$this->_exe->limit($count,$offsite);
		return $this->_exe;
	}
	
	function limitPage($page, $rowCount){
		$this->_exe->limitPage($page, $rowCount);
		return $this->_exe;
	}
	
	
	
	function select($format = false){
		
		return $this->_db->fetchAll($this->_exe);
	}
	
	function fetch($format = false){
		return $this->_db->fetchRow($this->_exe);
		
	}
	
	function add($bind){
		return $this->_db->insert($this->_table, $bind);
	}
	
	function getlastid(){
		return $this->_db->lastInsertId();
	}
	
 
}
